6.13 Test and define the following method
/**
* In a given ArrayList, remove all duplicates.
* The worstTime(n) is O(n2 ).
*
* @param list - the given ArrayList.
*
* @return - An ArrayList that is identical to list except only the first
* occurrence of duplicate elements remains.
*
* @throws NullPointerException - if list is null.
*
*/
public static ArrayList uniquefy (ArrayList list)
For example, suppose myList consists of references to Integer objects with the following values, in
sequence 3, 8, 6, 4, 8, 7, 8, 9, 4
Then the ArrayList returned by the call to uniquefy (myList) will consist of references to Integer
objects with the following values, in sequence
3, 8, 6, 4, 7, 9
 
 
View Solution
 
 
 
<< Back